﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace dev.queensland.web.webservices
{
    /// <summary>
    /// Summary description for NotificationWebService
    /// </summary>
    [WebService(Namespace = "http://dev.queensland.web/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class NotificationWebService : System.Web.Services.WebService
    {

        Microsoft.AspNet.SignalR.Client.HubConnection hubConnection = null;
        Microsoft.AspNet.SignalR.Client.IHubProxy chatHubProxy = null;


        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World from NotificationWebService";
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
        public void Notify(string moduleType, string title, string message)
        {
            //Context.Response.Clear();
            //Context.Response.ContentType = "application/json";
            //Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

            //System.Web.Script.Serialization.JavaScriptSerializer javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            //string message1 = "Hello World " + message + DateTime.Now.ToString();

            ////return javaScriptSerializer.Serialize(new Message(message1));
            //return new Message(message1);

            //hubConnection = new Microsoft.AspNet.SignalR.Client.HubConnection("http://localhost:80");
            //chatHubProxy = hubConnection.CreateHubProxy("chatHub");
            //hubConnection.Start();


            //return hubConnection.State.ToString();
            hubConnection = new Microsoft.AspNet.SignalR.Client.HubConnection("http://localhost:80");
            chatHubProxy = hubConnection.CreateHubProxy("chatHub");
            hubConnection.Start();
            chatHubProxy.Invoke("Send", "mytitle", "mymessage");


        }
    }
}
